import request from '@/utils/request'

// 获取购物车列表
export const getCartList = () => {
  return request({
    url: '/cart/list',
    method: 'get'
  })
}

// 添加商品到购物车
export const addToCart = (data) => {
  return request({
    url: '/cart/add',
    method: 'post',
    data
  })
}

// 更新购物车商品数量
export const updateCartItem = (id, data) => {
  return request({
    url: `/cart/update/${id}`,
    method: 'put',
    data
  })
}

// 切换购物车商品选中状态
export const toggleCartItem = (id, currentSelected) => {
  return request({
    url: `/cart/toggle/${id}`,
    method: 'put',
    data: {
      selected: currentSelected === 1 ? 0 : 1  // 切换选中状态
    }
  })
}

// 全选/取消全选
export const toggleAllCartItems = (data) => {
  return request({
    url: '/cart/toggle-all',
    method: 'put',
    data
  })
}

// 删除购物车商品
export const deleteCartItem = (id) => {
  return request({
    url: `/cart/delete/${id}`,
    method: 'delete'
  })
}

// 清空购物车
export const clearCart = () => {
  return request({
    url: '/cart/clear',
    method: 'delete'
  })
}

// 删除选中的商品
export const deleteSelectedCartItems = () => {
  return request({
    url: '/cart/delete-selected',
    method: 'delete'
  })
}





